package cn.gotom.pinggu.action;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;

import cn.gotom.coding.EncodingUtils;
import cn.gotom.core.service.UniversalService;
import cn.gotom.core.web.Constants;
import cn.gotom.core.web.action.MenuInf;
import cn.gotom.pinggu.pojos.Sjcjb;
import cn.gotom.pinggu.service.DataService;
import cn.gotom.pinggu.vo.Nsrxx;

import com.google.inject.Inject;

public class SjbdAction implements MenuInf
{
	protected final Logger log = Logger.getLogger(getClass());

	@Inject
	private UniversalService universalService;
	private String[] ids;
	private Sjcjb sjcjb;
	private Nsrxx nsrxx;
	private List<Sjcjb> dataList;
	@Inject
	private DataService dataService;
	private String actionmsg;

	public String taxpayer()
	{
		return "taxpayer";
	}

	public String findtaxpayer()
	{
		if (StringUtils.isEmpty(nsrxx.getNsrdm()) && StringUtils.isEmpty(nsrxx.getNsrmc()))
		{
			setActionmsg("请输入纳税人代码或名称！");
			return "taxpayer";
		}
		// Nsrxx nsr = null;
		// if (StringUtils.isNotEmpty(nsrxx.getNsrdm()))
		// {
		// nsr = dataService.getNsrxxByNsrdm(nsrxx.getNsrdm());
		// }
		// else if (StringUtils.isNotEmpty(nsrxx.getNsrmc()))
		// {
		// nsr = dataService.getNsrxxByNsrdm(nsrxx.getNsrmc());
		// }
		// if (nsr == null)
		// {
		// setActionmsg("该纳税人不存在，请输入正确的纳税人信息！");
		// return "taxpayer";
		// }
		return list();
	}

	public String input()
	{
		setActionmsg("");
		if (nsrxx == null)
		{
			nsrxx = new Nsrxx();
		}
		return "taxpayer";
	}

	public String list()
	{
		if (ids == null || ids.length == 0)
		{
			if (sjcjb != null)
			{
				sjcjb = universalService.get(Sjcjb.class, sjcjb.getId());
			}
			else
			{
				sjcjb = new Sjcjb();
			}
		}
		else
		{
			sjcjb = universalService.get(Sjcjb.class, ids[0]);
		}
		dataList = universalService.findAll(Sjcjb.class);
		for (Sjcjb o : this.dataList)
		{
			EncodingUtils.encoding(o, "cp850", "GBK");
		}
		return Constants.SUCCESS;
	}

	public String save()
	{

		return "";
	}

	@Override
	public String getName()
	{
		return "数据比对";
	}

	@Override
	public String getGroupName()
	{
		return "数据分析";
	}

	@Override
	public int getMenuSort()
	{
		return 300;
	}

	public String[] getIds()
	{
		return ids;
	}

	public void setIds(String[] ids)
	{
		this.ids = ids;
	}

	public Sjcjb getSjcjb()
	{
		return sjcjb;
	}

	public void setSjcjb(Sjcjb sjcjb)
	{
		this.sjcjb = sjcjb;
	}

	public Nsrxx getNsrxx()
	{
		return nsrxx;
	}

	public void setNsrxx(Nsrxx nsrxx)
	{
		this.nsrxx = nsrxx;
	}

	public List<Sjcjb> getDataList()
	{
		return dataList;
	}

	public void setDataList(List<Sjcjb> dataList)
	{
		this.dataList = dataList;
	}

	public String getActionmsg()
	{
		return actionmsg;
	}

	public void setActionmsg(String actionmsg)
	{
		this.actionmsg = actionmsg;
	}
}
